package leetcode;

import java.util.Stack;

/**
 *Leetcode232【用栈实现队列】
 * https://leetcode-cn.com/problems/implement-queue-using-stacks/
 */
public class StackImplementQueue {
    private Stack<Integer> stack1 = new Stack<>();
    private Stack<Integer> stack2 = new Stack<>();

    public StackImplementQueue() {

    }

    public void push(int x) {
        if (stack1.isEmpty()){
            stack1.push(x);
        }else {
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            stack1.push(x);
            while (!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
        }

    }

    public int pop() {
        return stack1.pop();
    }

    public int peek() {
        return stack1.peek();
    }

    public boolean empty() {
        return stack1.isEmpty();
    }
}
